package com.hisense.ovcloud.mqtt.business.config;

import com.hisense.ovcloud.commons.dto.common.AesKeyInfoInCache;
import com.hisense.ovcloud.commons.dto.common.ProductInfoInCache;
import com.hisense.ovcloud.commons.tools.LocalLFUCacheUtil;
import com.hisense.ovcloud.commons.tools.LocalTimedCacheUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class LocalCacheConfig {
    private final MqttBusinessProperties mqttBusinessProperties;

    public LocalCacheConfig(MqttBusinessProperties mqttBusinessProperties) {
        this.mqttBusinessProperties = mqttBusinessProperties;
    }

    @Bean
    @Qualifier("productInfoInCache")
    public LocalLFUCacheUtil<ProductInfoInCache> productInfoInCache(){
        return new LocalLFUCacheUtil<>(mqttBusinessProperties.getLocalcacheCapacity());
    }

    @Bean
    @Qualifier("aesKeyInfoInCache")
    public LocalTimedCacheUtil<AesKeyInfoInCache> aesKeyInfoInCache(){
        return new LocalTimedCacheUtil<>(mqttBusinessProperties.getCacheDefaultTimeoutSeconds(), mqttBusinessProperties.getSchedulePruneSecond());
    }
}
